package com.whisper.application.app.web.controller.front;

import com.whisper.application.service.domain.VrAct;
import com.whisper.application.service.domain.VrArt;
import com.whisper.application.service.domain.VrNotice;
import com.whisper.application.service.domain.VrPost;
import com.whisper.application.service.service.*;
import com.whisper.common.core.domain.AjaxResult;
import com.whisper.common.utils.StreamUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
public class IndexController {

    @Autowired
    private IVrPostService postService;
    @Autowired
    private IVrActService actService;
    @Autowired
    private IVrNoticeService noticeService;
    @Autowired
    private IVrArtService artService;
    @Autowired
    private IVrUserService userService;

    /**
     * 获取首页信息
     *
     * @return 结果
     */
    @GetMapping("/index")
    public void index(HttpServletResponse response)
    {
        AjaxResult ajax = AjaxResult.success();

        ajax.put("carousel", postService.selectVrPostOrderByCreateTimeLimit(4));
        ajax.put("userCount", userService.selectUserCount());
        ajax.put("actCount", actService.selectActCount());
        ajax.put("newsList", postService.selectGroupByPostListLimit(11));
        ajax.put("workList", postService.selectVrPostListLimit(new VrPost().setPostType("0"), 4));
        ajax.put("actList", actService.selectVrActVoListLimit(new VrAct(), 4));
        ajax.put("artList", artService.selectVrArtListLimit(new VrArt(), 4));
        ajax.put("noticeList", noticeService.selectNoticeListLimit(new VrNotice(), 11));
        StreamUtil.response(response, ajax);
    }

    /**
     * 获取首页信息
     *
     * @return 结果
     */
    @GetMapping("/news")
    public void newsData(HttpServletResponse response)
    {
        AjaxResult ajax = AjaxResult.success();

        ajax.put("carousel", postService.selectVrPostOrderByCreateTimeLimit(4));
        ajax.put("newsList", postService.selectGroupByPostListLimit(9));
        VrPost vrPost = new VrPost();
        vrPost.setStatus("1");
        vrPost.setType("1");
        ajax.put("workList", postService.selectVrPostList(vrPost));
        StreamUtil.response(response, ajax);
    }

}
